﻿using Commons.Responses;
using EntityModels.E04.Interactions;
using IRepositories;
using Microsoft.EntityFrameworkCore;
using ORM;
using System.Linq.Expressions;

namespace Repositories
{
    public class StarRepository : BaseRepository<int, Star>, IBaseRepository<int, Star>
    {
        public StarRepository(PSPDbContext context) : base(context)
        {
        }

        public override async Task<DatasResponse<Star>> GetAllAsync(Expression<Func<Star, bool>> predicate, Dictionary<string, bool> orderByFields = null)
        {
            IQueryable<Star> dbSet= Context.Set<Star>().Include(x => x.AppUser).Include(x => x.Children).ThenInclude(x => x.Photograph);
            dbSet = dbSet.OrderByDescending(x=>x.UpdateTime);
            var datas = await dbSet.Where(predicate).ToListAsync();
            var total = await dbSet.CountAsync();
            var result = new DatasResponse<Star>(total, datas);
            return result!;
        }
    }
}
